/*
 *  nautilus-svn-checkout.c - Subversion extension for Nautilus
 * 
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Author: Jack Xu Hong <jack.xu.hong@gmail.com>
 * 
 */

#include <config.h>

#include <gtk/gtk.h>
#include <glade/glade.h>

#include <svn_client.h>
#include <svn_cmdline.h>

#include "nautilus-svn-console.h"

#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), NAUTILUS_TYPE_SVN_CONSOLE, NautilusSvnConsolePriv))

typedef struct {
	GtkWidget *widget;
	gboolean cancelled;
} NautilusSvnConsolePriv;

G_DEFINE_TYPE (NautilusSvnConsole, nautilus_svn_console, GTK_TYPE_DIALOG);

static void svn_console_finalize (GObject *object);
static void svn_console_create_ui (NautilusSvnConsole *console);
static void svn_console_button_ok_clicked_cb (GtkWidget *widget, NautilusSvnConsole *console);
static void svn_console_button_cancel_clicked_cb (GtkWidget *widget, NautilusSvnConsole *console);
static void svn_console_destroy_cb (GtkWidget *widget, NautilusSvnConsole *console);

static void
nautilus_svn_console_class_init (NautilusSvnConsoleClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	object_class->finalize = svn_console_finalize;

	/*
	signals[FAILED] =
		g_signal_new ("failed",
			      G_TYPE_FROM_CLASS (klass),
			      G_SIGNAL_RUN_LAST,
			      0,
			      NULL, NULL,
			      nautilus_svn_marshal_VOID__VOID,
			      G_TYPE_NONE, 0);
	*/
	
	g_type_class_add_private (object_class, sizeof (NautilusSvnConsolePriv));
}

static void
nautilus_svn_console_init (NautilusSvnConsole *console)
{
	NautilusSvnConsolePriv *priv;

	priv = GET_PRIV (console);
	
	svn_console_create_ui (console);
}

static void
svn_console_finalize (GObject *object)
{
	NautilusSvnConsolePriv *priv;

	priv = GET_PRIV (object);

	G_OBJECT_CLASS (nautilus_svn_console_parent_class)->finalize (object);
}

static void
svn_console_create_ui (NautilusSvnConsole *console)
{
	NautilusSvnConsolePriv *priv;
	GladeXML *xml;
	GtkWidget *button_ok;
	GtkWidget *button_cancel;
	
	priv = GET_PRIV (console);

	xml = glade_xml_new (GLADEDIR "/" "nautilus-svn-console.glade", 
			             NULL, NULL);
	priv->widget = glade_xml_get_widget (xml, "dialog_console");
	
	g_signal_connect (priv->widget, 
	                  "destroy", 
	                  G_CALLBACK (svn_console_destroy_cb), 
	                  console);
	
	button_ok = glade_xml_get_widget (xml, "button_ok");
	g_signal_connect (button_ok, 
	                  "clicked", 
	                  G_CALLBACK (svn_console_button_ok_clicked_cb), 
	                  console);

	button_cancel = glade_xml_get_widget (xml, "button_cancel");
	g_signal_connect (button_cancel, 
	                  "clicked", 
	                  G_CALLBACK (svn_console_button_cancel_clicked_cb), 
	                  console);
	
	g_object_unref(xml);
}

static void svn_console_button_ok_clicked_cb (GtkWidget *widget, NautilusSvnConsole *console)
{
	NautilusSvnConsolePriv *priv = GET_PRIV (console);
	gtk_widget_destroy (priv->widget);
}

static void svn_console_button_cancel_clicked_cb (GtkWidget *widget, NautilusSvnConsole *console)
{
	NautilusSvnConsolePriv *priv = GET_PRIV (console);
	gtk_widget_destroy (priv->widget);
}

static void svn_console_destroy_cb (GtkWidget *widget, NautilusSvnConsole *console)
{
	g_free (console);
}

NautilusSvnConsole *
nautilus_svn_console_new (void)
{
	NautilusSvnConsole *console;
	
	console = g_object_new (NAUTILUS_TYPE_SVN_CONSOLE, NULL);

	svn_console_create_ui (console);
	
	return console;
}
